﻿/// <reference path="../../release/ajaxstack-core.js"/>
/// <reference path="../../release/jsApp.js"/>

function AjaxExamplesPageController(app, tagId)
{
	AjaxExamplesPageController.$baseConstructor.call(this, app, tagId);
}
AjaxExamplesPageController.extend(UiController, { type: 'AjaxExamplesPageController' },
{
	onAfterRender: function()
	{
		this.log.debug("AjaxExamples: onAfterRender(): ");

		var $context = this.app.getExamplesContext();

		$("#btnGetFactorial").click(function()
		{
			var forNumber = $("#txtGetFactorial").val();
			
			$context.getFactorial(forNumber);
		});

		$("#btnGetFibonacciNumbers").click(function()
		{
			var skip = $("#txtGetFibonacciNumbersSkip").val(),
				take = $("#txtGetFibonacciNumbersTake").val();

			$context.getFibonacciNumbers(skip, take);
		});
	},

	onGetFactorial: function(source, e)
	{
		$("#factorial-result").html(H.b(e.getResult().Result));
	},

	onGetFibonacciNumbers: function(source, e)
	{
		var html = H.ul({
			dataSource: e.getResult().Results,
			onItemDataBound: function(i, val) { return H.li(val); }
		});
		$("#fibonacci-result").html(html);
	}
});
AjaxExamplesPageController.getName = function() { return "ajaxExamples"; }
